<?php
/**
 * MVM_MALL 网上商店系统
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * 
 * @author :     www.mvmmall.com <admin@mvmmall.com> 
 * @version :    v4.X 
 * @module:      phpwind论坛系统
---------------------------------------------
 */
if(!defined('MVMMALL')){
    exit('Access Denied');
}
//插件的代码必须和文件名保持一致
$passport['phpwind']['name']    = 'phpwind论坛系统';
//描述
$passport['phpwind']['desc']    = 'phpwind论坛系统';
//版权信息
$passport['phpwind']['license']  = '版权所有www.mvmmall.com';
//接口需要的参数
$passport['phpwind']['cfg'] =array(
        array('name' => 'passport_api', 'value' => 'http://linux.mvmmall.com/phpwind/passport_client.php','label'=>'phpwind接口地址'),
        array('name' => 'passport_key', 'value' => 'UeHay:aR.QB8rCSA','label'=>'密 钥'),
        array('name' => 'charset', 'value' => 'gb2312','label'=>'数据库编码'),
        );
    
class phpwind
{
    var $cfg;
    
    function  phpwind($cfg = array())
    {
        foreach ($cfg AS $key=>$val)
        {
            $this->cfg[$val['name']] = $val['value'];
        }
    }
    
       //编码转换
    function charset($string)
    {
        if($this->cfg[charset]=='gb2312' || $this->cfg[charset]=='gbk'){
            $string=iconv("UTF-8","gb2312","$string");
        }
        return $string;
    }
    
    
/*提交请求 注册请求信息 $table_member 会员信息*/
function post_reg($table_member)	
	{ 
	}
	
/*提交请求 登陆请求信息 $table_member 会员信息*/
function post_login($table_member)	
	{  
	    $jumpurl = $this->cfg[passport_api];
	    //$forward=$GLOBALS[forward];
	    $db_pptkey= $this->cfg[passport_key];
	   
	    $userdb['username']	= $this->charset($table_member[member_id]);
	    $userdb['password']	= $table_member[member_pass];
	    $userdb['email']	= $table_member[member_email];
	    $userdb['time']		= time();
	    $userdb['cktime']	= $cktime ? $cktime : 'F';

	    $userdb_encode='';
	    foreach($userdb as $key=>$val){
	        $userdb_encode .= $userdb_encode ? "&$key=$val" : "$key=$val";
	    }
	    $db_hash=$db_pptkey;
	    $userdb_encode=str_replace('=','',$this->StrCode($userdb_encode));
        $verify = md5("login$userdb_encode$forward$db_pptkey");
	   header('Location:'.$jumpurl.'?action=login&forward='.rawurlencode($forward).'&verify='.rawurlencode($verify).'&userdb='.rawurlencode($userdb_encode));
	   exit;
	}
	/*提交退出请求**/
  function post_logout(){
        $login_id = $this->charset($GLOBALS[m_check_id]);
        $db = $GLOBALS[db];
        $result = $db->query("SELECT member_id,member_pass, member_email FROM $GLOBALS[mvm_member_table] WHERE member_id='$login_id'");
        $table_member = $db->fetch_array($result);
        $jumpurl = $this->cfg[passport_api];
	    $forward=$GLOBALS[forward];
	    $db_pptkey= $this->cfg[passport_key];
	    $userdb['username']	= $this->charset($table_member[member_id]);
	    $userdb['password']	= $table_member[member_pass];
	    $userdb['email']	= $table_member[member_email];
	    $userdb['time']		= time();
	    $userdb['cktime']	= $cktime ? $cktime : 'F';

	    $userdb_encode='';
	    foreach($userdb as $key=>$val){
	        $userdb_encode .= $userdb_encode ? "&$key=$val" : "$key=$val";
	    }
	    $db_hash=$db_pptkey;
	    $userdb_encode=str_replace('=','',$this->StrCode($userdb_encode));
        $verify = md5("quit$userdb_encode$forward$db_pptkey");
	   header('Location:'.$jumpurl.'?action=quit&forward='.rawurlencode($forward).'&verify='.rawurlencode($verify).'&userdb='.rawurlencode($userdb_encode));
	   exit;
      
  }
  function StrCode($string,$action='ENCODE'){
	$key	= substr(md5($_SERVER["HTTP_USER_AGENT"].$this->cfg[passport_key]),8,18);
	$string	= $action == 'ENCODE' ? $string : base64_decode($string);
	$len	= strlen($key);
	$code	= '';
	for($i=0; $i<strlen($string); $i++){
		$k		= $i % $len;
		$code  .= $string[$i] ^ $key[$k];
	}
	$code = $action == 'DECODE' ? $code : base64_encode($code);
	return $code;
}
}
